<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button onclick="handle()">请求</button>
    <img src="" alt="">


    <script>
        function jsonp(url, cb) {
            return new Promise((resolve, reject) => {
                const script = document.createElement('script');
                window[cb] = function (data) {
                    resolve(data); // 后端返回的数据
                }
                script.src = `${url}?cb=${cb}`
                document.body.appendChild(script);
            })
        }

        function handle() {
            jsonp('http://localhost:3000', 'callback').then(res => {
                console.log(res);
            })
        }
    </script>
</body>




</html>